package com.kehongborui.net.socket.udp;


import java.io.IOException;
import java.net.*;

/**
 * upd 服务端
 */
public class UdpClient {
    public static void main(String[] args) throws IOException {
        DatagramSocket server = new DatagramSocket(9997);  // 实例化 udp 服务端
        // 创建数据包对象 InetAddress.getLocalHost() == InetAddress.getByName("localhost")
        String msg = "我是客户端";
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), msg.getBytes().length, InetAddress.getByName("localhost"), 9998);
        System.out.println("客户端开始发送数据");
        server.send(packet);  // 发送数据
        server.close();
    }
}
